#include <iostream>
#include <cstring>
//字符串切割
char * myStrtok(char * source, const char * delim)
{
    static char * delimHeader = nullptr;//只初始化一次 延长生命周期
    if (source == nullptr)
    {
        if (delimHeader == NULL)
            return nullptr;
        source = delimHeader;
    }
    char * target = strstr(source, delim);
    if (target == nullptr)//没找到
    {
        delimHeader = nullptr;
        return source;
    }
    else
    {
        *target = '\0';
        delimHeader = target + strlen(delim);
        return source;
    }
}

int main()
{
    char str[] = "zhangsan,lisi,wangwu";
    char * s = myStrtok(str, ",");//将","->'\0' 只适用于字符数组 
    while (s != nullptr)
    {
        std::cout<<s<<std::endl;
        s = myStrtok(nullptr, ",");
    }
    return 0;
}